<?php
  require_once("includes/config.php"); 
//Edit Pop-up"
  //dump($_POST);
  if($_SERVER["REQUEST_METHOD"] == "POST")
  {
     if(isset($_POST['internet']))
        $internet = 1;
      else
        $internet = 0;
     
     if(isset($_POST['park']))
        $park = 1;
      else
        $park = 0;
     
     if(isset($_POST['elevator']))
        $elevator = 1;
      else
        $elevator = 0;
     
     if(isset($_POST['clean']))
        $clean = 1;
      else
        $clean = 0;
     
     if(isset($_POST['phoneguide']))
        $phoneguide = 1;
      else
        $phoneguide = 0;
     
     if(isset($_POST['oven']))
        $oven = 1;
      else
        $oven = 0;
        
     if(isset($_POST['newspapaer']))
        $newspapaer = 1;
      else
        $newspapaer = 0;
        
     if(isset($_POST['microwave']))
        $microwave = 1;
      else
        $microwave = 0;
        
     if(isset($_POST['phoneguide']))
        $phoneguide = 1;
      else
        $phoneguide = 0;
        
     if(isset($_POST['chkWashingMachine']))
        $chkWashingMachine = 1;
      else
        $chkWashingMachine = 0;
        
     if(isset($_POST['resturant']))
        $resturant = 1;
      else
        $resturant = 0;
        
     if(isset($_POST['chkIron']))
        $chkIron = 1;
      else
        $chkIron = 0;
        
     if(isset($_POST['fridge']))
        $fridge = 1;
      else
        $fridge = 0;
        
     if(isset($_POST['chkFoodTable']))
        $chkFoodTable = 1;
      else
        $chkFoodTable = 0;
        
     if(isset($_POST['hall']))
        $hall = 1;
      else
        $hall = 0;
        
     if(isset($_POST['chkKitchen']))
        $chkKitchen = 1;
      else
        $chkKitchen = 0;
        
     if(isset($_POST['qibala']))
        $qibala = 1;
      else
        $qibala = 0;
              
    
    $results = query("SELECT * from apartments where apart_name = ? and owner_id = ?",$_POST['name'],$_SESSION['user_id']);
    if(!empty($results))
    {
      $_SESSION['error_message'] = "اسم الوحده الذى ادخلته موجود مسبقاً"; 
    }
    else
    {
      $result = query("
      INSERT INTO apartments 
          (apart_name, floor, rooms, bathrooms,single_beds ,double_beds,safes,TV,cooler_type,room_type,status,internet,park,elevator,clean_service,
            telephone,newspapers,	qebla,rest_list,refregrator,hall,oven,microwave,washer,iron,food_table,kitchen,additional_notes,owner_id) 
      VALUES 
          (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
          
      $_POST['name'],$_POST['floor'],$_POST['room_num'],$_POST['bathrooms'],$_POST['single_beds'],$_POST['double_beds'],$_POST['safe'],$_POST['tv'],$_POST['cooler_type'],$_POST['apart_type'],
      $_POST['apart_status'],$internet,$park,$elevator,$clean,$phoneguide,$newspapaer,$qibala,$resturant,$fridge,
      $hall,$oven,$microwave,$chkWashingMachine,$chkIron,$chkFoodTable,$chkKitchen,$_POST['txtComments'],$_SESSION['user_id']);
      $_SESSION['success_message'] = "تم اضافة الوحده بنجاح"; 
     }
      redirect("apartments.php");

 }
	?>